using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour
{
	
	public Player Player;
	public AudioClip Sound;
	public float Offset;
	public float Velocity;
	public float Limit;
	
	Vector3 Default;
	bool Released;
	
	void Start()
	{
		Default = transform.position;
	}
	
	void Update()
	{
		if (Released)
		{
			if (Vector3.Distance(transform.position, Player.transform.position - new Vector3(Player.Offset.x, 0.0f , Player.Offset.y) ) >= Limit)
				OnTriggerEnter(null);
		}
		else if (Input.GetButton("Fire1") || Input.GetButton("Jump"))
		{
			audio.PlayOneShot(Sound);
			transform.position = Player.transform.position + new Vector3(0.0f, 0.0f, Offset);
			rigidbody.velocity = new Vector3(0.0f, 0.0f, Velocity);
			Released = true;
		}
	}
	
	void OnTriggerEnter(Collider collider)
	{
		transform.position = Default;
		rigidbody.velocity = Vector3.zero;
		Released = false;
	}
	
}